package com.hyacinth.web.listener;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.hyacinth.common.constant.SysConstant;
import com.hyacinth.core.sysmgr.domain.SysUser;

public class SessionListener implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent event) {
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		HttpSession session = event.getSession();
		ServletContext application = session.getServletContext();
		SysUser u = (SysUser)session.getAttribute(SysConstant.SYS_SESSION_USER);
		if(u!=null) {
			Map<String,String> map = (HashMap<String,String>)application.getAttribute(SysConstant.SYS_APPLICATION_USER);
			map.remove(u.getUsername());
		}
		session.invalidate();
	}

}
